package leetcode.L1000;

import java.util.Stack;

public class EX1047 {
    public String removeDuplicates(String S) {
        StringBuffer stack = new StringBuffer();
        int point = -1;
        for (int i = 0; i < S.length(); i++) {
            if(point>=0&&S.charAt(i)==stack.charAt(point)){
                stack.deleteCharAt(point);
                point--;
            }else{
                point++;
                stack.append(S.charAt(i));
            }
        }
        return stack.toString();
    }
}
